package com.hpx.javaeye.model;

import com.hpx.javaeye.util.JsonUtil;

public class User {
	private String domain;
	private String name;
	private String id;

	public User() {
	}

	public User(String domain, String name, String id) {
		this.domain = domain;
		this.name = name;
		this.id = id;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public User extractFromJson(String target) {
		String[][] result = JsonUtil.extractFromJson(target);
		for (int i = 0; i < result.length; i++) {
			for (int j = 0; j < result[i].length; j++) {
				if (result[i][j].equals("name")) {
					this.setName(result[i + 1][j]);
				} else if (result[i][j].equals("id")) {
					this.setId(result[i + 1][j]);
				} else if (result[i][j].equals("domain")) {
					this.setDomain(result[i + 1][j]);
				}
			}
		}
		return this;
	}

	public String toString() {
		return "User is : name:" + this.getName() + ",id:" + this.getId()
				+ ",domain:" + this.getDomain();
	}
}
